package com.base64;

import java.io.IOException;

import org.junit.Test;

import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;

public class TestBase64Encoder {
	
	/**
	 * 使用BASE64加密解密
	 * BASE64加密可逆
	 * @throws IOException
	 */
	@Test
	public void test1() throws IOException {
		String s = "username";
		//BASE64加密
		BASE64Encoder encoder = new BASE64Encoder();
		s = encoder.encode(s.getBytes("utf-8"));
		System.out.println(s);
		//BASE64解密
		BASE64Decoder decoder = new BASE64Decoder();
		byte[] bytes = decoder.decodeBuffer(s);
		s = new String(bytes, "utf-8");
		System.out.println(s);
	}
}
